#!/usr/bin/env python
# @Date    : 2022-04-25
# @Author  : Bright (brt2@qq.com)
# @Link    : https://gitee.com/brt2
# @Version : 0.1.0

from sanic import Sanic as Application
from sanic.response import text, json

def app_run(app, *args, **kwargs):
    if "reload" in kwargs:
        kwargs["auto_reload"] = kwargs["reload"]
        del kwargs["reload"]
    if "access_log" not in kwargs:
        print(">>> 关闭输出访问日志，以提升性能")
        kwargs["access_log"] = False
    return app.run(*args, **kwargs)

def make_app(app_name, **kwargs):
    app = Application(app_name, **kwargs)
    # 添加CORS
    try:
        from sanic_cors import CORS
        CORS(app)
    except ImportError:
        pass
    # 添加openapi
    try:
        from sanic_openapi import openapi3_blueprint
        app.blueprint(openapi3_blueprint)
    except ImportError:
        pass
    return app
